<!-- HTML header for doxygen 1.8.8-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <!-- For Mobile Devices -->
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
        <meta name="generator" content="Doxygen 1.9.1"/>
        <script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
        <title>libevdev: Event handling</title>
        <!--<link href="tabs.css" rel="stylesheet" type="text/css"/>-->
        <script type="text/javascript" src="dynsections.js"></script>
        <link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
        <link href="doxygen.css" rel="stylesheet" type="text/css" />
        <link href="bootstrap.css" rel="stylesheet" type="text/css"/>
<link href="customdoxygen.css" rel="stylesheet" type="text/css"/>
<link href="libevdevdoxygen.css" rel="stylesheet" type="text/css"/>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
        <script type="text/javascript" src="doxy-boot.js"></script>
    </head>
    <body>
        <nav class="navbar navbar-default" role="navigation">
            <div class="container">
                <div class="navbar-header">
                    <a class="navbar-brand">libevdev 1.13.0</a>
                </div>
            </div>
        </nav>
        <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
            <div class="content" id="content">
                <div class="container">
                    <div class="row">
                        <div class="col-sm-12 panel panel-default" style="padding-bottom: 15px;">
                            <div style="margin-bottom: 15px;">
<!-- end header part -->
<!-- Generated by Doxygen 1.9.1 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="summary">
<a href="#enum-members">Enumerations</a> &#124;
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle">
<div class="title">Event handling</div>  </div>
</div><!--header-->
<div class="contents">

<p>Functions to handle events and fetch the current state of the event.  
<a href="#details">More...</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="enum-members"></a>
Enumerations</h2></td></tr>
<tr class="memitem:ga56c288d9f2e4c1632986c4e218c494e9"><td class="memItemLeft" align="right" valign="top">enum &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__events.html#ga56c288d9f2e4c1632986c4e218c494e9">libevdev_read_flag</a> { <a class="el" href="group__events.html#gga56c288d9f2e4c1632986c4e218c494e9a1f13a19641d6dafcf01a86a6389800f8">LIBEVDEV_READ_FLAG_SYNC</a>
, <a class="el" href="group__events.html#gga56c288d9f2e4c1632986c4e218c494e9ac0d6ee19551eecf76f1ede4f36252418">LIBEVDEV_READ_FLAG_NORMAL</a>
, <a class="el" href="group__events.html#gga56c288d9f2e4c1632986c4e218c494e9a5198e5c9cc98b75f73f61b104d6a674c">LIBEVDEV_READ_FLAG_FORCE_SYNC</a>
, <a class="el" href="group__events.html#gga56c288d9f2e4c1632986c4e218c494e9a0a348d44362a7e515b40a4ed4d528e19">LIBEVDEV_READ_FLAG_BLOCKING</a>
 }</td></tr>
<tr class="separator:ga56c288d9f2e4c1632986c4e218c494e9"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga4a96221b3c7f54dfb86035d952154e3a"><td class="memItemLeft" align="right" valign="top">enum &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__events.html#ga4a96221b3c7f54dfb86035d952154e3a">libevdev_read_status</a> { <a class="el" href="group__events.html#gga4a96221b3c7f54dfb86035d952154e3aab053221fc1c9630eee7111b75aa0aec7">LIBEVDEV_READ_STATUS_SUCCESS</a>
, <a class="el" href="group__events.html#gga4a96221b3c7f54dfb86035d952154e3aa8d70b14a38204fde4ad433023baa545a">LIBEVDEV_READ_STATUS_SYNC</a>
 }</td></tr>
<tr class="separator:ga4a96221b3c7f54dfb86035d952154e3a"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:gabb96c864e836c0b98788f4ab771c3a76"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__events.html#gabb96c864e836c0b98788f4ab771c3a76">libevdev_next_event</a> (struct libevdev *dev, unsigned int flags, struct input_event *ev)</td></tr>
<tr class="memdesc:gabb96c864e836c0b98788f4ab771c3a76"><td class="mdescLeft">&#160;</td><td class="mdescRight">Get the next event from the device.  <a href="group__events.html#gabb96c864e836c0b98788f4ab771c3a76">More...</a><br /></td></tr>
<tr class="separator:gabb96c864e836c0b98788f4ab771c3a76"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gae18fbfb59064c9c4b9d5db2d8cb23784"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__events.html#gae18fbfb59064c9c4b9d5db2d8cb23784">libevdev_has_event_pending</a> (struct libevdev *dev)</td></tr>
<tr class="memdesc:gae18fbfb59064c9c4b9d5db2d8cb23784"><td class="mdescLeft">&#160;</td><td class="mdescRight">Check if there are events waiting for us.  <a href="group__events.html#gae18fbfb59064c9c4b9d5db2d8cb23784">More...</a><br /></td></tr>
<tr class="separator:gae18fbfb59064c9c4b9d5db2d8cb23784"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<p>Functions to handle events and fetch the current state of the event. </p>
<p>libevdev updates its internal state as the event is processed and forwarded to the caller. Thus, the libevdev state of the device should always be identical to the caller's state. It may however lag behind the actual state of the device. </p>
<h2 class="groupheader">Enumeration Type Documentation</h2>
<a id="ga56c288d9f2e4c1632986c4e218c494e9"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga56c288d9f2e4c1632986c4e218c494e9">&#9670;&nbsp;</a></span>libevdev_read_flag</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">enum <a class="el" href="group__events.html#ga56c288d9f2e4c1632986c4e218c494e9">libevdev_read_flag</a></td>
        </tr>
      </table>
</div><div class="memdoc">
<table class="fieldtable">
<tr><th colspan="2">Enumerator</th></tr><tr><td class="fieldname"><a id="gga56c288d9f2e4c1632986c4e218c494e9a1f13a19641d6dafcf01a86a6389800f8"></a>LIBEVDEV_READ_FLAG_SYNC&#160;</td><td class="fielddoc"><p>Process data in sync mode. </p>
</td></tr>
<tr><td class="fieldname"><a id="gga56c288d9f2e4c1632986c4e218c494e9ac0d6ee19551eecf76f1ede4f36252418"></a>LIBEVDEV_READ_FLAG_NORMAL&#160;</td><td class="fielddoc"><p>Process data in normal mode. </p>
</td></tr>
<tr><td class="fieldname"><a id="gga56c288d9f2e4c1632986c4e218c494e9a5198e5c9cc98b75f73f61b104d6a674c"></a>LIBEVDEV_READ_FLAG_FORCE_SYNC&#160;</td><td class="fielddoc"><p>Pretend the next event is a SYN_DROPPED and require the caller to sync. </p>
</td></tr>
<tr><td class="fieldname"><a id="gga56c288d9f2e4c1632986c4e218c494e9a0a348d44362a7e515b40a4ed4d528e19"></a>LIBEVDEV_READ_FLAG_BLOCKING&#160;</td><td class="fielddoc"><p>The fd is not in O_NONBLOCK and a read may block. </p>
</td></tr>
</table>

</div>
</div>
<a id="ga4a96221b3c7f54dfb86035d952154e3a"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga4a96221b3c7f54dfb86035d952154e3a">&#9670;&nbsp;</a></span>libevdev_read_status</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">enum <a class="el" href="group__events.html#ga4a96221b3c7f54dfb86035d952154e3a">libevdev_read_status</a></td>
        </tr>
      </table>
</div><div class="memdoc">
<table class="fieldtable">
<tr><th colspan="2">Enumerator</th></tr><tr><td class="fieldname"><a id="gga4a96221b3c7f54dfb86035d952154e3aab053221fc1c9630eee7111b75aa0aec7"></a>LIBEVDEV_READ_STATUS_SUCCESS&#160;</td><td class="fielddoc"><p><a class="el" href="group__events.html#gabb96c864e836c0b98788f4ab771c3a76" title="Get the next event from the device.">libevdev_next_event()</a> has finished without an error and an event is available for processing. </p>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="group__events.html#gabb96c864e836c0b98788f4ab771c3a76" title="Get the next event from the device.">libevdev_next_event</a> </dd></dl>
</td></tr>
<tr><td class="fieldname"><a id="gga4a96221b3c7f54dfb86035d952154e3aa8d70b14a38204fde4ad433023baa545a"></a>LIBEVDEV_READ_STATUS_SYNC&#160;</td><td class="fielddoc"><p>Depending on the <a class="el" href="group__events.html#gabb96c864e836c0b98788f4ab771c3a76" title="Get the next event from the device.">libevdev_next_event()</a> read flag: </p>
<ul>
<li>libevdev received a SYN_DROPPED from the device, and the caller should now resync the device, or,</li>
<li>an event has been read in sync mode.</li>
</ul>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="group__events.html#gabb96c864e836c0b98788f4ab771c3a76" title="Get the next event from the device.">libevdev_next_event</a> </dd></dl>
</td></tr>
</table>

</div>
</div>
<h2 class="groupheader">Function Documentation</h2>
<a id="gae18fbfb59064c9c4b9d5db2d8cb23784"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gae18fbfb59064c9c4b9d5db2d8cb23784">&#9670;&nbsp;</a></span>libevdev_has_event_pending()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int libevdev_has_event_pending </td>
          <td>(</td>
          <td class="paramtype">struct libevdev *&#160;</td>
          <td class="paramname"><em>dev</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Check if there are events waiting for us. </p>
<p>This function does not read an event off the fd and may not access the fd at all. If there are events queued internally this function will return non-zero. If the internal queue is empty, this function will poll the file descriptor for data.</p>
<p>This is a convenience function for simple processes, most complex programs are expected to use select(2) or poll(2) on the file descriptor. The kernel guarantees that if data is available, it is a multiple of sizeof(struct input_event), and thus calling <a class="el" href="group__events.html#gabb96c864e836c0b98788f4ab771c3a76" title="Get the next event from the device.">libevdev_next_event()</a> when select(2) or poll(2) return is safe. You do not need <a class="el" href="group__events.html#gae18fbfb59064c9c4b9d5db2d8cb23784" title="Check if there are events waiting for us.">libevdev_has_event_pending()</a> if you're using select(2) or poll(2).</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">dev</td><td>The evdev device, already initialized with <a class="el" href="group__init.html#ga6658ac490d68c307ff8b8d1536c12b44" title="Set the fd for this struct and initialize internal data.">libevdev_set_fd()</a> </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>On failure, a negative errno is returned. </dd></dl>
<dl class="retval"><dt>Return values</dt><dd>
  <table class="retval">
    <tr><td class="paramname">0</td><td>No event is currently available </td></tr>
    <tr><td class="paramname">1</td><td>One or more events are available on the fd</td></tr>
  </table>
  </dd>
</dl>
<dl class="section note"><dt>Note</dt><dd>This function is signal-safe. </dd></dl>

</div>
</div>
<a id="gabb96c864e836c0b98788f4ab771c3a76"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gabb96c864e836c0b98788f4ab771c3a76">&#9670;&nbsp;</a></span>libevdev_next_event()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int libevdev_next_event </td>
          <td>(</td>
          <td class="paramtype">struct libevdev *&#160;</td>
          <td class="paramname"><em>dev</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">unsigned int&#160;</td>
          <td class="paramname"><em>flags</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">struct input_event *&#160;</td>
          <td class="paramname"><em>ev</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Get the next event from the device. </p>
<p>This function operates in two different modes: normal mode or sync mode.</p>
<p>In normal mode (when flags has <a class="el" href="group__events.html#gga56c288d9f2e4c1632986c4e218c494e9ac0d6ee19551eecf76f1ede4f36252418">LIBEVDEV_READ_FLAG_NORMAL</a> set), this function returns <a class="el" href="group__events.html#gga4a96221b3c7f54dfb86035d952154e3aab053221fc1c9630eee7111b75aa0aec7">LIBEVDEV_READ_STATUS_SUCCESS</a> and returns the event in the argument <code>ev</code>. If no events are available at this time, it returns -EAGAIN and ev is undefined.</p>
<p>If the current event is an EV_SYN SYN_DROPPED event, this function returns <a class="el" href="group__events.html#gga4a96221b3c7f54dfb86035d952154e3aa8d70b14a38204fde4ad433023baa545a">LIBEVDEV_READ_STATUS_SYNC</a> and ev is set to the EV_SYN event. The caller should now call this function with the <a class="el" href="group__events.html#gga56c288d9f2e4c1632986c4e218c494e9a1f13a19641d6dafcf01a86a6389800f8">LIBEVDEV_READ_FLAG_SYNC</a> flag set, to get the set of events that make up the device state delta. This function returns <a class="el" href="group__events.html#gga4a96221b3c7f54dfb86035d952154e3aa8d70b14a38204fde4ad433023baa545a">LIBEVDEV_READ_STATUS_SYNC</a> for each event part of that delta, until it returns -EAGAIN once all events have been synced. For more details on what libevdev does to sync after a SYN_DROPPED event, see <a class="el" href="syn_dropped.html">SYN_DROPPED handling</a>.</p>
<p>If a device needs to be synced by the caller but the caller does not call with the <a class="el" href="group__events.html#gga56c288d9f2e4c1632986c4e218c494e9a1f13a19641d6dafcf01a86a6389800f8">LIBEVDEV_READ_FLAG_SYNC</a> flag set, all events from the diff are dropped after libevdev updates its internal state and event processing continues as normal. Note that the current slot and the state of touch points may have updated during the SYN_DROPPED event, it is strongly recommended that a caller ignoring all sync events calls <a class="el" href="group__mt.html#gad22e2420be668b56ef486cde2e98c5dd" title="Get the currently active slot.">libevdev_get_current_slot()</a> and checks the ABS_MT_TRACKING_ID values for all slots.</p>
<p>If a device has changed state without events being enqueued in libevdev, e.g. after changing the file descriptor, use the <a class="el" href="group__events.html#gga56c288d9f2e4c1632986c4e218c494e9a5198e5c9cc98b75f73f61b104d6a674c">LIBEVDEV_READ_FLAG_FORCE_SYNC</a> flag. This triggers an internal sync of the device and <a class="el" href="group__events.html#gabb96c864e836c0b98788f4ab771c3a76" title="Get the next event from the device.">libevdev_next_event()</a> returns <a class="el" href="group__events.html#gga4a96221b3c7f54dfb86035d952154e3aa8d70b14a38204fde4ad433023baa545a">LIBEVDEV_READ_STATUS_SYNC</a>. Any state changes are available as events as described above. If <a class="el" href="group__events.html#gga56c288d9f2e4c1632986c4e218c494e9a5198e5c9cc98b75f73f61b104d6a674c">LIBEVDEV_READ_FLAG_FORCE_SYNC</a> is set, the value of ev is undefined.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">dev</td><td>The evdev device, already initialized with <a class="el" href="group__init.html#ga6658ac490d68c307ff8b8d1536c12b44" title="Set the fd for this struct and initialize internal data.">libevdev_set_fd()</a> </td></tr>
    <tr><td class="paramname">flags</td><td>Set of flags to determine behaviour. If <a class="el" href="group__events.html#gga56c288d9f2e4c1632986c4e218c494e9ac0d6ee19551eecf76f1ede4f36252418">LIBEVDEV_READ_FLAG_NORMAL</a> is set, the next event is read in normal mode. If <a class="el" href="group__events.html#gga56c288d9f2e4c1632986c4e218c494e9a1f13a19641d6dafcf01a86a6389800f8">LIBEVDEV_READ_FLAG_SYNC</a> is set, the next event is read in sync mode. </td></tr>
    <tr><td class="paramname">ev</td><td>On success, set to the current event. </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>On failure, a negative errno is returned. </dd></dl>
<dl class="retval"><dt>Return values</dt><dd>
  <table class="retval">
    <tr><td class="paramname">LIBEVDEV_READ_STATUS_SUCCESS</td><td>One or more events were read of the device and ev points to the next event in the queue </td></tr>
    <tr><td class="paramname">-EAGAIN</td><td>No events are currently available on the device </td></tr>
    <tr><td class="paramname">LIBEVDEV_READ_STATUS_SYNC</td><td>A SYN_DROPPED event was received, or a synced event was returned and ev points to the SYN_DROPPED event</td></tr>
  </table>
  </dd>
</dl>
<dl class="section note"><dt>Note</dt><dd>This function is signal-safe. </dd></dl>

</div>
</div>
</div><!-- contents -->
<!-- HTML footer for doxygen 1.8.8-->
<!-- start footer part -->
</div>
</div>
</div>
</div>
</div>
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.9.1
</small></address>
</body>
</html>
